package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ElderInfo;
import com.example.admin.service.ElderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ElderController {

    @Autowired
    private ElderService elderService;

     @GetMapping("/getElderInfoPage")
    public Result getElderInfoPage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {

         PageHelper.startPage(pageNumber,pageSize);
        List<ElderInfo> elderInfos= elderService.getElderInfoPage();
        return Result.success(new PageInfo(elderInfos));

     }

     @DeleteMapping("/deleteElderInfoById/{id}")
    public Result deleteById(@PathVariable Integer id) {
         Result result=elderService.deleteById(id);
         return result;
     }

     @PostMapping("/addElderInfo")
    public Result addElderInfo(@RequestBody ElderInfo elderInfo) {
        Result result= elderService.addElderInfo(elderInfo);
        return result;
     }

     @PutMapping("/editeElderInfo")
    public Result editElderInfo(@RequestBody ElderInfo elderInfo) {
        Result resul= elderService.editElderInfo(elderInfo);
        return resul;
     }

     @GetMapping("/selectElderInfoByName")
    public Result<PageInfo> selectElderInfoByName(@RequestParam String name) {
         PageHelper.startPage(1,10);
        List<ElderInfo> elderInfos= elderService.selectElderInfoByName(name);
        return Result.success(new PageInfo(elderInfos));
     }
}
